

package com.classload.apigateway;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component
public class LogGatewayFilterFactory extends AbstractGatewayFilterFactory<LogGatewayFilterFactory.Config> {
    public LogGatewayFilterFactory() {
        super(LogGatewayFilterFactory.Config.class);
    }


    @Override
    public GatewayFilter apply(LogGatewayFilterFactory.Config config) {
        return (exchange, chain) -> {
            if (config.cacheLog) {
                System.err.println("开启缓存日志");
            }
            if (config.consoleLog) {
                System.err.println("开启控制台日志");
            }
            return chain.filter(exchange);
        };
    }

    @Override
    public List<String> shortcutFieldOrder() {
        return Arrays.asList("cacheLog", "consoleLog");
    }

    @Data
    @NoArgsConstructor
    public static class Config {
        private Boolean cacheLog;
        private Boolean consoleLog;
    }
}
